extends Node2D

export(Array,PackedScene) var enemy_tscn_array

var current_enemys:Array

var max_enemy_num=4

var born_interval=[2.0,4.0]

export(String,FILE) var enemys_born_file

var enemys_born:Array
var pause=false
func set_pause(pause_time:float):
	pause=true
	$PauseTimer.start(pause_time)

func _on_Pause_timeout():
	pause=false
	pass # Replace with function body.


signal born_num_change_sigal

func _ready():
	var file = File.new()
	file.open(enemys_born_file, File.READ)
	enemys_born=JSON.parse(file.get_as_text()).result
	file.close()
	emit_signal("born_num_change_sigal",enemys_born.size())
	var _e=get_tree().current_scene.connect("level_start_signal",self,"_on_timeout")
	
func _on_timeout():
	if current_enemys.size()<max_enemy_num:
		if enemys_born.size()>0:
			var enemy_born=  enemys_born.pop_front()
			emit_signal("born_num_change_sigal",enemys_born.size())
			get_child(enemy_born.bornIndex).start_born(enemy_tscn_array[enemy_born.enemyType],enemy_born.isRed)
		else:
			return
	$BornTimer.start(rand_range(born_interval[0],born_interval[1]))
	pass # Replace with function body.

func remove_enemy(enemy):
	current_enemys.erase(enemy)
	if enemys_born.size()==0 and current_enemys.size()==0:
		get_tree().current_scene.level_win()
	print("当前坦克"+str(current_enemys))
	
func boom_enemys():
	for i in current_enemys.size():
#		这里在坦克死亡时会自动将其移出数组，所以用index为0的就可以
		current_enemys[0].die()
		print("ddd")
	

